package com.itfitness.googlemappoi.http

import androidx.lifecycle.MutableLiveData
import com.blankj.utilcode.util.LogUtils
import com.itfitness.googlemappoi.bean.BaseBean
import com.itfitness.googlemappoi.bean.GeocodeAddressBean
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response

/**
 *
 * @ProjectName:    GoogleMapPOI
 * @Package:        com.itfitness.googlemappoi
 * @ClassName:      AA
 * @Description:     java类作用描述
 * @Author:         itfitness
 * @CreateDate:     2021/12/11 11:15
 * @UpdateUser:     更新者：
 * @UpdateDate:     2021/12/11 11:15
 * @UpdateRemark:   更新说明：
 */
/**
 * Call的扩展函数，对请求的封装
 */
fun <T:BaseBean> Call<T>.putValue2Data(clazz: Class<T>,liveData: MutableLiveData<T>){
    enqueue(object : Callback<T>{
        override fun onResponse(
            call: Call<T>,
            response: Response<T>
        ) {
            response.body()?.let { liveData.value = it }
        }
        override fun onFailure(call: Call<T>, t: Throwable) {
            liveData.value = clazz.newInstance().apply {
                exception = t
            }
            LogUtils.eTag("返回",t.message)
        }
    })
}
